package com.cbh.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cbh.api.model.ApiResult;
import com.cbh.domain.service.PlatePrefixService;
import com.cbh.entity.PlatePrefix;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(description = "车牌前缀管理")
@RestController
@RequestMapping("/sign/v3/plate/prefix")
public class PlatePrefixController {
	@Autowired
	PlatePrefixService ppService;

	/**
	 * 保存车牌前缀信息
	 * 
	 * @param product
	 * @return
	 */
	@ApiOperation(value = "车牌前缀信息保存", httpMethod = "POST")
	@RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json")
	public ApiResult<String> save(
			@ApiParam(value = "车牌前缀信息", required = true) @RequestBody(required = true) PlatePrefix ob) {
		ApiResult<String> apiResult = new ApiResult<>();
		try {
			String re = ppService.save(ob);
			return apiResult.success(re);
		} catch (Exception e) {
			return apiResult.fail(e.getMessage());
		}
	}

	/**
	 * 获取全部车牌前缀信息
	 * 
	 * @return
	 */
	@ApiOperation(value = "获取全部车牌前缀信息", httpMethod = "GET")
	@RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json")
	public ApiResult<List<PlatePrefix>> getAll() {
		ApiResult<List<PlatePrefix>> apiResult = new ApiResult<>();
		try {
			List<PlatePrefix> obs = ppService.getAll();
			return apiResult.success(obs);
		} catch (Exception e) {
			return apiResult.fail(e.getMessage());
		}
	}

	/**
	 * 获取车牌前缀信息
	 * 
	 * @param proId
	 * @return
	 */
	@ApiOperation(value = "获取车牌前缀信息", httpMethod = "GET")
	@ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "id", dataType = "String", required = true) })
	@RequestMapping(value = "{id}", method = RequestMethod.GET, produces = "application/json")
	public ApiResult<PlatePrefix> getOne(@PathVariable("id") String id) {
		ApiResult<PlatePrefix> apiResult = new ApiResult<>();
		try {
			PlatePrefix ob = ppService.getOne(id);
			return apiResult.success(ob);
		} catch (Exception e) {
			return apiResult.fail(e.getMessage());
		}
	}

	/**
	 * 删除车牌前缀信息
	 * 
	 * @param proId
	 * @return
	 */
	@ApiOperation(value = "删除车牌前缀信息", httpMethod = "DELETE")
	@ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "id", dataType = "String", required = true) })
	@RequestMapping(value = "{id}", method = RequestMethod.DELETE, produces = "application/json")
	public ApiResult<Boolean> delete(@PathVariable("id") String id) {
		ApiResult<Boolean> apiResult = new ApiResult<>();
		try {
			Boolean re = ppService.delete(id);
			return apiResult.success(re);
		} catch (Exception e) {
			return apiResult.fail(e.getMessage());
		}
	}
}
